package com.ruoyi.web.controller.gallery;

import java.util.List;

import com.ruoyi.system.domain.gallery.GalleryCase;
import com.ruoyi.system.service.gallery.GalleryCaseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图库案例说明Controller
 * 
 * @author 张少丛
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/gallery/case")
public class GalleryCaseController extends BaseController
{
    @Autowired
    private GalleryCaseService galleryCaseService;

    /**
     * 查询图库案例说明列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(GalleryCase galleryCase)
    {
        startPage();
        List<GalleryCase> list = galleryCaseService.selectGalleryCaseList(galleryCase);
        return getDataTable(list);
    }

    /**
     * 导出图库案例说明列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:export')")
    @Log(title = "图库案例说明", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GalleryCase galleryCase)
    {
        List<GalleryCase> list = galleryCaseService.selectGalleryCaseList(galleryCase);
        ExcelUtil<GalleryCase> util = new ExcelUtil<GalleryCase>(GalleryCase.class);
        return util.exportExcel(list, "case");
    }

    /**
     * 获取图库案例说明详细信息
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:query')")
    @GetMapping(value = "/{galleryCaseId}")
    public AjaxResult getInfo(@PathVariable("galleryCaseId") Long galleryCaseId)
    {
        return AjaxResult.success(galleryCaseService.selectGalleryCaseById(galleryCaseId));
    }

    /**
     * 新增图库案例说明
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:add')")
    @Log(title = "图库案例说明", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GalleryCase galleryCase)
    {
        return toAjax(galleryCaseService.insertGalleryCase(galleryCase));
    }

    /**
     * 修改图库案例说明
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:edit')")
    @Log(title = "图库案例说明", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GalleryCase galleryCase)
    {
        return toAjax(galleryCaseService.updateGalleryCase(galleryCase));
    }

    /**
     * 删除图库案例说明
     */
    @PreAuthorize("@ss.hasPermi('gallery:case:remove')")
    @Log(title = "图库案例说明", businessType = BusinessType.DELETE)
	@DeleteMapping("/{galleryCaseIds}")
    public AjaxResult remove(@PathVariable Long[] galleryCaseIds)
    {
        return toAjax(galleryCaseService.deleteGalleryCaseByIds(galleryCaseIds));
    }
}
